const http = require("http")

var arr = [
    {
        "name":"小明",
        "score": 90
    }
]

// 再写一个接口 添加学生数据接口。
// https://www.runoob.com/nodejs/node-js-get-post.html

const server = http.createServer((req, res)=> {
    // 这是cors ，允许前端进行跨域。
    res.setHeader("Access-Control-Allow-Origin", "*");
    res.setHeader("Access-Control-Allow-Headers", "Content-Type,Content-Length, Authorization, Accept,X-Requested-With");
    res.setHeader("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
    res.setHeader("X-Powered-By",' 3.2.1')


    res.setHeader("Content-Type", "application/json;charset=utf-8")
    console.log(req.url)
    if(req.url === "/api/getStudent") {
        res.end(JSON.stringify(arr))
    }
})

server.listen(5000, ()=> {
    console.log("服务器创建成功")
})